<include file="Common:layout" />
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>数据还原</h3>
                <h5>网站系统数据还原</h5>
            </div>
        </div>
    </div>
    <!-- 操作说明 -->
    <div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;">
        <div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>
            <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
            <span title="收起提示" id="explanationZoom" style="display: block;"></span>
        </div>
        <ul>
            <li> 数据还原, 点击恢复选项进行数据库导入.</li>
            <li> 导入的SQL文件语句必须按照MYSQL的语法编写</li>
        </ul>
    </div>
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>sql文件列表</h3>
                <h5>(备份文件数量：{$filenum}，占空间大小：{$total|format_bytes})</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="sign" axis="col0">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </th>
                        <th align="left" abbr="article_title" axis="col3" class="">
                            <div style="text-align: left; width: 200px;" class="">文件名称</div>
                        </th>
                        <th align="center" abbr="ac_id" axis="col4" class="">
                            <div style="text-align: center; width: 50px;" class="">卷号</div>
                        </th>
                        <th align="center" abbr="article_show" axis="col5" class="">
                            <div style="text-align: center; width: 50px;" class="">压缩</div>
                        </th>
                        <th align="center" abbr="article_time" axis="col6" class="">
                            <div style="text-align: center; width: 150px;" class="">数据大小</div>
                        </th>
                        <th align="center" abbr="article_show" axis="col7" class="">
                            <div style="text-align: center; width: 150px;" class="">备份时间</div>
                        </th>
                        <th align="center" abbr="article_show" axis="col8" class="">
                            <div style="text-align: center; width: 130px;" class="">状态</div>
                        </th>
                        <th align="center" axis="col1" class="handle">
                            <div style="text-align: center; width: 250px;">操作</div>
                        </th>
                        <th style="width:100%" axis="col9">
                            <div></div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton">
                    <form class="navbar-form form-inline" action="{:U('Tools/restoreUpload')}" name="change_System" method="post" enctype="multipart/form-data">
                        <input type="file" class="btn" name="sqlfile" id="sqlfile">
                        <input type="submit" class="ncap-btn-big ncap-btn-green" value="上传并执行sql文件">
                    </form>
                </div>
            </div>
            <div style="clear:both"></div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table>
                    <tbody>
                    <foreach name="list" item="vo" key="k" >
                        <tr data-id="{$vo.name}">
                            <td class="sign">
                                <div style="width: 24px;"><i class="ico-check"></i></div>
                            </td>
                            <td align="left" class="">
                                <div style="text-align: left; width: 200px;">{$vo.basename}</div>
                            </td>
                            <td align="center" class="">
                                <div style="text-align: center; width: 50px;">{$vo.part}</div>
                            </td>
                            <td align="center" class="">
                                <div style="text-align: center; width: 50px;">{$vo.compress}</div>
                            </td>
                            <td align="center" class="">
                                <div style="text-align: center; width: 150px;">{$vo.size|format_bytes}</div>
                            </td>
                            <td align="center" class="">
                                <div style="text-align: center; width: 150px;">{$vo.time|date="Y-m-d H:i:s",###}</div>
                            </td>
                            <td align="center" class="">
                                <div style="text-align: center; width: 130px;">-</div>
                            </td>
                            <td align="center" class="handle">
                                <div style="text-align: center; width: 170px; max-width:170px;">
                                    <a href="{:U('import?time='.$vo['time'])}" class="btn blue db-import"><i class="fa fa-repeat"></i>恢复</a>
                                    <a href="{:U('Tools/downFile',array('time'=>$vo['time']))}" class="btn green"><i class="fa fa-download"></i>下载</a>
                                    <a class="btn red"><i class="fa fa-trash"></i>删除</a>
                                    <input type="hidden" class="time" value="{$vo['time']}"/>
                                </div>
                            </td>
                            <td align="" class="" style="width: 100%;">
                                <div>&nbsp;</div>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

    });

    $(".db-import").click(function(){
        var self = this;
        $.get(self.href, success, "json");
        window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
        return false;
        function success(data){
            if(data.part||data.start){
                $(self).parent().parent().prev().find('div').text(data.info);
                $.ajax({
                    type: 'post',
                    url: "{:U('Tools/import')}",
                    data: {
                        part:data.part,
                        start:data.start
                    },
                       success: function (msg) {
                           setTimeout(function(){
                               $(self).parent().parent().prev().find('div').text(msg.info);
                               },1000);
                       }
                });
            } else {
                layer.alert(data.info,{icon:2});
            }
        }
    });

    $(".red").click(function () {
        //删除按钮
        var res = $(this).next().val();
        layer.confirm('确认删除？',{
            btn:['确定','取消']//按钮
        },function () {
            $.ajax({
                type:'post',
                url:"{:U('del')}",
                data:{
                    time: res
                },
                success:function (msg) {
                    if(msg == '1'){
                        layer.msg("删除成功",{time:1000})
                        location.reload();
                    }else if(msg=='-2'){
                        layer.msg("参数错误",{icon:2,time:1000})
                        location.reload();
                    }else{
                        layer.msg("备份文件删除失败，请检查权限！",{icon:2,time:1000})
                        location.reload();
                    }
                }
            })
        })
    })
</script>
</body>
</html>